import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:oktoast/oktoast.dart';
import 'package:provider/provider.dart';

import 'package:senkoo_platform/base_provider/base_provider.dart';
import 'package:senkoo_platform/config/config.dart';
import 'package:senkoo_platform/views/login_modular/login_page.dart';
import 'package:senkoo_platform/views/main_modular/main_page.dart';
import 'package:senkoo_platform/views/splash_mudular/splash_page.dart';
import 'package:sp_util/sp_util.dart';
import 'package:flutter/services.dart';
// ignore: depend_on_referenced_packages
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:senkoo_platform/base_import/base_import.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await SpUtil.getInstance();

  SystemChrome.setPreferredOrientations(<DeviceOrientation>[
    DeviceOrientation.landscapeLeft,
    DeviceOrientation.landscapeRight
  ]).then((_) {
    SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarBrightness: Brightness.dark);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  });

  runApp(const SenkooPlatform());
}

class SenkooPlatform extends StatelessWidget {
  const SenkooPlatform({super.key});

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider<BaseProvider>(
      create: (_) => BaseProvider(),
      child: ScreenUtilInit(
        designSize: const Size(1366, 768),
        minTextAdapt: true,
        splitScreenMode: true,
        builder: (_, child) {
          return MaterialApp(
            localizationsDelegates: const [
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
              GlobalCupertinoLocalizations.delegate,
            ],
            supportedLocales: const [Locale('zh', 'CN')],
            debugShowCheckedModeBanner: AppConfig.setDebug ? true : false,
            home: const HomePage(),
          );
        },
      ),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({
    super.key,
  });

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return OKToast(
        backgroundColor: Colors.black54,
        textPadding:
            const EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0),
        radius: 4.r,
        child: LoginPage(),
        textStyle: TextStyle(
          fontSize: 12.sp,
          color: Standard.colorFFFFFF,
          decoration: TextDecoration.none,
          fontWeight: fontW400,
        ),
        position: ToastPosition.center);
  }
}
